<?php

namespace Home\Model;
use Think\Model;
class PassbyPushModel extends Model {
    public function addPassbyPush($data){
        return $this->data($data)->add();
    }

    public function modPassbyPush($data){
        return $this->where(array('deviceserialno'=>$data['deviceserialno']))->save($data);
    }

    public function closePassbyPush($deviceserialno){
        return $this->where(array('deviceserialno'=>$deviceserialno))->save(array('status'=>1));
    }

    public function getPassbyPush($deviceserialno){
        return $this->where(array('deviceserialno'=>$deviceserialno))->select();
    }

    public function getPassbyPushList($data){
        //获取Datatables发送的参数 必要
        $draw = $data['draw'];    //这个值直接返回给前台
        //搜索框
        $search = trim($data['search']['value']);    //获取前台传过来的过滤条件
        if(strlen($search) > 0) {
            $where['deviceserialno|Passbyfile|Passbyname|pushtime'] = array("EXP","LIKE BINARY '%".$search."%'");
        }
        $recordsTotal = $this->count();
        $recordsFiltered =  $this->where($where)->count();

        $result = $this
            ->where($where)
            ->order(array('pushtime'=>'desc'))
            ->limit(intval($data['start']),intval($data['length']))
            ->select();

        $list = array(
            "draw" => intval($draw),
            "recordsTotal" => intval($recordsTotal),
            "recordsFiltered"=>intval($recordsFiltered),
            "search"=>$where,
            "status"=>$result?true:false,
            "data" =>$result?$result:"",
        );
        return $list;
        return $this->order(array('pushtime'=>'desc'))->page($page, $pagesize)->select();
    }

}

